﻿<%@ Control Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.UserControl" %>
<%@ Import Namespace="Portal.Core" %>
<%@ Import Namespace="Portal.Data" %>
<%@ Import Namespace="Portal.Data.Security" %>
<asp:Panel ID="pnSignout" runat="server" DefaultButton="SignOut">
    <div class="Menu">
        <center style="font-size: 14px; padding: 5px 0 10px 0;">
            Welcome <font style="font-weight: bold; color: green">
                <asp:Label ID="lbAccount" runat="server" Text=""></asp:Label></font>
        </center>
        <ul>
            <li><a href="<%=CoreContext.basepath %>Admin/Polls/PollSettings.aspx" target="_blank">Voting manager</a></li>
            <li><a href="<%=CoreContext.basepath%>Admin/MasterCreate.aspx" target="_blank">Copy
                page</a></li>
            <li><a href="<%=CoreContext.basepath%>Admin/Manager.aspx" target="_blank">Config Manager</a></li>
            <li><a href="<%=CoreContext.basepath%>Admin/FileManager.aspx" target="_blank">Style
                Manager</a></li>
            <li><a href="<%=CoreContext.basepath%>Admin/SQLManager.aspx" target="_blank">Run SQL
                Execute</a></li>
            <li><a id="a1" href="#">Đổi mật khẩu</a></li>
        </ul>
        <br class="clear" />
        <asp:Button CssClass="CommandSignOut" ID="SignOut" runat="server" Text="SignOut"
            OnClick="SignOut_Click" />
    </div>
</asp:Panel>
<div class="popup" id="popupchangepass" style="width: 300px;">
    <span class="bClose"><span>X</span></span>
    <h2>Đổi mật khẩu</h2>
    <br />
    <div id="message" style="display: none;">
    </div>
    <div style="width: 100%;">
        <div style="float: left; width: 30%; line-height: 25px;">
            Mật khẩu cũ
        </div>
        <div style="float: right; width: 60%;">
            <input type="password" value="" id="valoldpass" name="valoldpass" style="width: 100%;" />
        </div>
        <br class="clearfix" />
        <div style="float: left; width: 30%; line-height: 25px;">
            Mật khẩu mới
        </div>
        <div style="float: right; width: 60%;">
            <input type="password" value="" id="valnewpass" name="valnewpass" style="width: 100%;" />
        </div>
        <br class="clearfix" />
        <div style="float: left; width: 30%; line-height: 25px;">
            Nhập lại
        </div>
        <div style="float: right; width: 60%;">
            <input type="password" value="" id="valconfirmpass" name="valconfirmpass" style="width: 100%;" />
        </div>
        <br class="clearfix" />
        <div style="float: left; width: 30%;">
        </div>
        <div style="float: right; width: 60%;">
            <input id="bSubmitChange" type="button" value="Đổi mật khẩu" />
            <input id="bcancel" type="button" value="Bỏ qua" />
        </div>
    </div>
</div>
<script type="text/javascript">
    jQuery(document).ready(function ($) {
        $('#a1').bind('click', function (e) {
            // Prevents the default action to be triggered. 
            e.preventDefault();

            // Triggering bPopup when click event is fired
            $('#popupchangepass').bPopup({
                modalClose: false,
                opacity: 0.6,
                positionStyle: 'fixed' //'fixed' or 'absolute'
            });
        });

        $('.bClose, #bcancel').bind('click', function () {
            $('#popupchangepass').bPopup().close();
        });
        $('#bSubmitChange').bind('click', function () {
            if (confirm('Chấp nhận đổi mật khẩu mới chứ?')) {
                $.ajax({
                    url: '/Ajax.aspx',
                    dataType: 'json',
                    data: {
                        p: 'User',
                        act: 'changePassword',
                        oldp: $('#valoldpass').val(),
                        newp: $('#valnewpass').val(),
                        confirm: $('#valconfirmpass').val()
                    },
                    success: function (data) {
                        $('#message').text(data.msg).show();
                        if (data.err == '0') {
                            $('#message').attr('class', 'success');
                            $('#valoldpass').val('');
                            $('#valnewpass').val('');
                            $('#valconfirmpass').val('');
                        }
                        else {
                            $('#message').attr('class', 'failed');
                        }
                    }
                });
            }
        });
    });
</script>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (PortalContext.CurrentUser == null)
        {
            Response.Redirect("admin_login.aspx");
        }
        else
        {
            lbAccount.Text = PortalContext.CurrentUser.FullName;
        }
    }

    protected void SignOut_Click(object sender, EventArgs e)
    {
        SecurityProvider.Instance.LogOut();
        Response.Redirect("admin_login.aspx");
    }
</script>
